package SimulatorComponents;

import java.io.FileNotFoundException;
import java.io.PrintStream;

import java.util.Scanner;

import Exceptions.EmptyMemoryException;
import Exceptions.InvalidArrayLengthException;
import Exceptions.InvalidMemoryAllocationException;

/**
 * 
 * esta clase tiene 2 usos: inicializar y manejar los componentes del gui e inicializar el objeto tipo Simulator  
 * ese objeto Simulator tiene un objeto AR2RISC que es el micro
 * Al objeto Simulator se le aplica la operacion de loadProgram() y simulate()
 * 
 * 
 * 
 *
 */
public class SimulatorControl {

	/**
	 * @param args
	 * @throws InvalidMemoryAllocationException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String args[]) throws FileNotFoundException, InvalidMemoryAllocationException {


		Scanner in = new Scanner(System.in);
		System.out.println("Please enter 0 for debug mode or 1 for complete execution of input file code");
		int mode = in.nextInt();
		
		while( mode < 0 || mode > 1 ){
			System.out.println("INCORRECT SELECTION");
			System.out.println("Please enter 0 for debug mode or 1 for complete execution of input file code");
			in = new Scanner(System.in);
			mode = in.nextInt();
		}	
		
		Simulator mySimulator = new Simulator(mode);

		try{
			int instructionCount = mySimulator.loadProgram();
			mySimulator.simulate(instructionCount);
		}
		
		catch(IndexOutOfBoundsException e){
			
			
			e.printStackTrace();
			//for( int i = 0; i < e.getStackTrace().length; i++ )
				//System.out.println( e.getStackTrace()[i] );			
		}
		catch(InvalidArrayLengthException e){
			e.printStackTrace();
		}
		catch(FileNotFoundException e){
			e.printStackTrace();
		}
		catch(InvalidMemoryAllocationException e){
			e.printStackTrace();
		}
		catch(EmptyMemoryException e){
			e.printStackTrace();
		}
		catch(StackOverflowError e){
			e.printStackTrace();
		}
		
		
		finally{

		
		}

	}

}
